package com.scuec.groupfive.controller;

import com.scuec.groupfive.entity.AnswerRecord;
import com.scuec.groupfive.service.AnswerRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/answer-records")
@CrossOrigin
public class AnswerRecordController {

    @Autowired
    private AnswerRecordService answerRecordService;

    @GetMapping("/latest")
    public ResponseEntity<?> getLatestAnswerRecord(
        @RequestParam Long userId,
        @RequestParam Long questionId
    ) {
        AnswerRecord record = answerRecordService.getLatestRecord(userId, questionId);
        if (record != null) {
            return ResponseEntity.ok(record);
        } else {
            return ResponseEntity.status(404).body("No record found");
        }
    }
} 